package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import util.DbUtil;

import dao.ListPricingDao;
import dao.ListUserDao;

public class AddPricingServlet extends HttpServlet {

	DbUtil dbUtil=new DbUtil();
	ListPricingDao listpricingdao=new ListPricingDao();
	
	public void wrong1(){
        String msg="空";
        int type=JOptionPane.YES_NO_CANCEL_OPTION;
        String title="空";
        JOptionPane.showMessageDialog(null, msg, title, type);
    }
	
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
		String pricingName=new String(request.getParameter("pricingName").getBytes("ISO-8859-1"),"UTF-8");
        String baseFee=new String(request.getParameter("baseFee").getBytes("ISO-8859-1"),"UTF-8");
        String rateFee=new String(request.getParameter("rateFee").getBytes("ISO-8859-1"),"UTF-8");
        String pricingDesc=new String(request.getParameter("userName").getBytes("ISO-8859-1"),"UTF-8");
	
        if(pricingName.length()==0||baseFee.length()==0||rateFee.length()==0||pricingDesc.length()==0){
            wrong1();
//            response.sendRedirect("addPricing.jsp");
        
        }else{
            try{
                Connection con=null;
                con=dbUtil.getCon();
                ListPricingDao listpricingdao=new ListPricingDao();
                listpricingdao.addPricing(con,pricingName,baseFee,rateFee,pricingDesc);
            }catch(Exception e){
            	e.printStackTrace();
            	}
            }
        response.sendRedirect("ListPricingServlet");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

	
	

}
